from config import setting
import aioredis
from utils.logger import logger
from fastapi import Request

async def get_redis_pool():
    # 初始化 Redis 连接池
    logger.info("初始化Redis 连接池")
    try:
        session  = await aioredis.from_url(setting.REDIS_DSN, encoding="utf-8", decode_responses=True)
        return  session
    except Exception as e:
        logger.error("初始化 Redis 连接池失败:{}".format(e))
    finally:
        pass


async def get_redis_client(request: Request):
    async with request.app.state.redis  as redis:
        return redis


